// SPDX-License-Identifier: GPL-2.0
/* smc-test.c - smc test driver
 *
 * Copyright (C) 2016-2018, LomboTech Co.Ltd.
 * Author: lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/device.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/err.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/of.h>
#include "common.h"
#include "../drivers/smc/smc.h"
#include "../drivers/smc/uapi/smc.h"
#include "../drivers/smc/smc_app.h"

#undef MOD_NAME
#define MOD_NAME	"SMC_TEST"	/* for print message */
#define SMC_NAME	"smc0"		/* smc device name */

struct contact test_data[] = {
	{"zhangsan", "12345678901"},
	{"zhangsan", "333333333333"},
	{"lisi", "44444444444"},
	{"wangwu", "55555555555"},
	{"zhangsan", "333333333333"},
	{"zhangsanzhangsa", "33333333333"},
	{"", "33333333333"},
	{"zhangsan", ""},
	{"zhangsanzhangsa", ""},
	{"", "333333333333"},
	{"zhangsanzhangsa", "333333333333"},
	{"", ""},
};

u8 message_data[][200] = {
	"this is a test message1",
	"this is a test message2                                                                                                                                                         ",
	"",
};

u8 test[4] = {0x11, 0x11, 0x11, 0x11};

/* smc test project, operations are read and write */
void smc_test(void)
{
	int i, n;

	PRT_INFO("start smc test\n");
	smc_get_iccid();
	smc_reset_select_directory();
	smc_get_imsi();
	smc_reset_select_directory();
	smc_get_contact(1);
	smc_reset_select_directory();
	smc_get_lp();
	smc_reset_select_directory();
	smc_write_lp(test);
	smc_reset_select_directory();
	smc_get_lp();

	n = ARRAY_SIZE(test_data);
	for (i = 0; i < n; i++) {
		PRT_INFO("this is %d contact\n", i+1);
		smc_write_contact(test_data[i], i+1);
		smc_reset_select_directory();
		smc_get_contact(i+1);
		smc_reset_select_directory();
	}
	n = ARRAY_SIZE(message_data);
	for (i = 0; i < n; i++) {
		PRT_INFO("this is %d message\n", i+1);
		smc_write_message(message_data[i], i+1);
		smc_reset_select_directory();
		smc_get_message(i+1);
		smc_reset_select_directory();
	}
	smc_clear_message(1);
//	smc_reset_select_directory();
//	smc_get_message(1);
//	smc_reset_select_directory();
//	smc_write_message(message_data[0],1);
//	smc_reset_select_directory();
//	smc_get_message(1);

	PRT_INFO("end smc test\n");
}
